package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.service.AskForLeaveService;
import com.hlw.hr_man.serviceImpl.AskForLeaveServiceImpl;

/**
 * 
 * @ClassName: IsExistAflApplyController
 * @Description: 处理判断是否存在请假申请请求
 * @author 唐明
 * @date 2016年9月20日 上午10:14:07
 *
 */
public class IsExistAflApplyController extends HttpServlet{

	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */ 
	private static final long serialVersionUID = 1L;

	AskForLeaveService aflService = new AskForLeaveServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//得到当前登录用户
		EmployeeModel employee = (EmployeeModel) req.getSession().getAttribute("loginEmployee");
		//得到当前用户的角色id
		int role_id = employee.getRole_id();
		//判断当前用户的角色id是否为7或1 ，是则进行处理  ，  
		if (role_id == 7 || role_id == 1) {
			int temp = aflService.getApplyAflCount();
			PrintWriter pw = resp.getWriter();
			if (temp > 0) {
				//如果存在请假申请  则返回"1"
				pw.write("1");
			} else {
				//不存在请假申请  返回"0"
				pw.write("0");
			}
		}
	}
}
